package pers.course.exam;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

class Person {
    SimpleDateFormat sFormat = new SimpleDateFormat("H:mm:ss");
    String name = "";
    int Accept = 0, total = 0;
    boolean[] isac = null;
    int[] penalty = null;
    Date[] acdate = null;
    Date date1 = null;

    Person(String s, int n, Date date) {
        Accept = 0;
        name = s;
        isac = new boolean[n];
        penalty = new int[n];
        acdate = new Date[n];
        total = n;
        date1 = date;
    }

    void accept(int name, Date date) {
        if (isac[name] || Main.minus(Main.end, date) < 0)
            return;
        Accept++;
        isac[name] = true;
        acdate[name] = date;
    }

    void wrong(int name, Date date) {
        if (Main.minus(Main.end, date) < 0)
            return;
        if (!isac[name] || Main.minus(acdate[name], date) > 0)
            penalty[name]++;
    }

    long Value() {
        long ans = 0;
        for (int i = 0; i != total; i++)
            if (isac[i])
                ans += Main.minus(acdate[i], date1) + (long) penalty[i] * 1000 * 20 * 60;
        return ans;
    }

    @SuppressWarnings("deprecation")
    private String named() throws ParseException {
        long v = Value();
        int t = (int) v / (24 * 60 * 60 * 1000);
        Date d = sFormat.parse(sFormat.format(v));
        String sdate = sFormat.format(d);
        return (d.getHours() + 24 * t - 8 < 0 ? d.getHours() + 24 * t + 16 : d.getHours() + 24 * t - 8)
                + sdate.substring(sdate.length() - 6, sdate.length());
    }

    public String toString() {
        String anString = name + " " + Accept;
        for (int i = 0; i != total; i++)
            if (isac[i])
                anString += " " + sFormat.format(Main.minus(acdate[i], date1) - 8 * 1000 * 60 * 60);
            else
                anString += " " + -penalty[i];
        try {
            return anString + " " + named();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }
}

public class Main {
    static int n = 0;
    static Date end = null;

    static String comd(String s1) {
        String[] strings = s1.split(" ");
        return strings[7] + " " + strings[8];
    }

    public static long minus(Date d1, Date d2) {
        Calendar c1 = Calendar.getInstance(), c2 = Calendar.getInstance();
        c1.setTime(d1);
        c2.setTime(d2);
        return c1.getTimeInMillis() - c2.getTimeInMillis();
    }

    public static String[] problems = null;

    public static void main(String args[]) throws ParseException, IOException {
        Person[] persons = new Person[100];
        Scanner sc = new Scanner(new File("input.in"));
        FileOutputStream fileOutputStream = new FileOutputStream(new File("output.out"));
        DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);
        TreeMap<String, Integer> person = new TreeMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date start = sdf.parse(sc.next() + " " + sc.next());
        end = sdf.parse(sc.next() + " " + sc.next());
        sc.nextLine();
        problems = sc.nextLine().split(" ");
        ArrayList<String> arrayList = new ArrayList<>();
        while (sc.hasNext())
            arrayList.add(sc.nextLine());
        Collections.sort(arrayList, (o1, o2) -> {
            try {
                return (int) minus(sdf.parse(comd(o1)), sdf.parse(comd(o2)));
            } catch (ParseException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
            return 0;
        });
        for (String ss : arrayList) {
            String[] strings = ss.split(" ");
            if (minus(sdf.parse(strings[7] + " " + strings[8]), start) < 0
                    || minus(sdf.parse(strings[7] + " " + strings[8]), end) > 0)
                continue;
            if (!person.keySet().contains(strings[1])) {
                persons[person.size()] = new Person(strings[1], problems.length, start);
                person.put(strings[1], person.size());
            }
            if (strings[3].equals("Accepted")) {
                for (int i = 0; i != problems.length; i++)
                    if (problems[i].equals(strings[2]))
                        persons[person.get(strings[1])].accept(i, sdf.parse(strings[7] + " " + strings[8]));
            } else {
                for (int i = 0; i != problems.length; i++)
                    if (problems[i].equals(strings[2]))
                        persons[person.get(strings[1])].wrong(i, sdf.parse(strings[7] + " " + strings[8]));
            }
        }
        Arrays.sort(persons, 0, person.size(), (o1, o2) -> o1.name.compareTo(o2.name));
        Arrays.sort(persons, 0, person.size(),
                (o2, o1) -> (int) (o1.Accept == o2.Accept ? o2.Value() - o1.Value() : o1.Accept - o2.Accept));
        dataOutputStream.writeBytes("Rank Name Solved");
        for (String s : problems)
            dataOutputStream.writeBytes(" " + s);
        dataOutputStream.writeBytes(" Penalty\n");
        for (int i = 0; i != person.size(); i++)
            dataOutputStream.writeBytes(i + 1 + " " + persons[i].toString() + '\n');
        sc.close();
    }
}